const { ApolloServer, gql } = require('apollo-server-express');
const { ApolloServerPluginDrainHttpServer } = require('apollo-server-core');
const express = require('express');
const http = require('http');
const typeDefs = gql`     
    type Teacher{
        name:String,
        title:String,
        id:ID
    }
    type Query{
        name:String,
        age:Int,
        teachers:[Teacher]
    }
`
const teachers = [
    { name: 'jw', title: '讲师', id: '001', home: { address: '天龙苑' } },
    { name: 'zry', title: '专家', id: '002', home: { address: '天通苑' } }
]
const resolvers = {
    Query: {
        name: () => 'zf',
        age: () => 12,
        teachers: () => teachers,
        // getTeacher(parent, args, context) { // parent是父查询 , args是用户的参数 ,context是查询的上下文
        //     return teachers.find(item=>item.id == args.id)
        // }
    }
}

const server =  new ApolloServer({
    typeDefs,
    resolvers
});
(async () => {
    let { url } = await server.listen();
    console.log(`server start ${url}`)
})()



// 我们一般在用apollo的时候 还是会和主流的框架在一起使用 express . koa